import requests


class IhrmDepApi(object):
    # 添加部门
    @classmethod
    def add_dep(cls, req_header, req_body):
        return requests.post(url="http://ihrm-test.itheima.net/api/company/department", headers=req_header, json=req_body)

    # 查询部门
    @classmethod
    def query_dep(cls, dep_id, req_header):
        return requests.get(url="http://ihrm-test.itheima.net/api/company/department/" + dep_id, headers=req_header)

    # 修改部门
    @classmethod
    def modify_dep(cls, dep_id, req_header, req_body):
        return requests.put(url="http://ihrm-test.itheima.net/api/company/department/" + dep_id, headers=req_header,
                            json=req_body)

    # 删除部门
    @classmethod
    def delete_dep(cls, dep_id, req_header):
        return requests.delete(url="http://ihrm-test.itheima.net/api/company/department/" + dep_id, headers=req_header)


if __name__ == '__main__':
    req_header = {"Authorization": "2ee145df-56cc-49c5-b334-116afe74a4c5"}
    req_body = {"name": "排大雷部", "code": "001"}
    # 添加部门自测
    resp = IhrmDepApi.add_dep(req_header, req_body)
    print("添加部门结果：", resp.json())

    # 查询部门自测
    dep_id = "1516428627472908288"
    resp = IhrmDepApi.query_dep(dep_id, req_header)
    print("查询部门结果：", resp.json())

    # 修改部门自测
    m_req_body = {"name": "造雷部", "code": "008"}
    resp = IhrmDepApi.modify_dep(dep_id, req_header, m_req_body)
    print("修改部门结果：", resp.json())

    # 删除部门自测
    resp = IhrmDepApi.delete_dep(dep_id, req_header)
    print("删除部门结果：", resp.json())